// stdafx.cpp : source file that includes just the standard includes
//	IOPSocketServer.pch will be the pre-compiled header
//	stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

HANDLE CreateNewCompletionPort(DWORD dwNumberOfThreads)
{
    return (CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 
        dwNumberOfThreads));
}

BOOL AssociateDeviceWithCompletionPort(HANDLE hCompletionPort, 
                                       HANDLE hDevice, ULONG_PTR pCompletionKey)
{
    HANDLE h = CreateIoCompletionPort(hDevice, hCompletionPort, 
        pCompletionKey, 0);
    return (h == hCompletionPort);
}

template<> UINT AFXAPI HashKey<SOCKADDR_IN&> (SOCKADDR_IN& addr)
{
    return addr.sin_addr.s_addr + addr.sin_port;
}

template<> BOOL AFXAPI CompareElements<SOCKADDR_IN, SOCKADDR_IN>
(
    const SOCKADDR_IN* pElement1, 
    const SOCKADDR_IN* pElement2
)
{
    ENSURE(pElement1 != NULL && pElement2 != NULL);
    ASSERT(AfxIsValidAddress(pElement1, sizeof(SOCKADDR_IN), FALSE));
    ASSERT(AfxIsValidAddress(pElement2, sizeof(SOCKADDR_IN), FALSE));

    if (pElement1->sin_port == pElement2->sin_port && 
        pElement1->sin_addr.s_addr == pElement2->sin_addr.s_addr)
        return TRUE;

    return FALSE;
}

